#@layout()
#define main()
<div class="container">
    <div class="row">
        <div class="col-lg-8">
            <form id="add" enctype="multipart/form-data" action="/app/add" method="post" onsubmit="return add()">
                <div class="form-row form-group">
                    <label for="name">名称:</label>
                    <input id="name" name="name" type="text" class="form-control">
                </div>
                <div class="form-row form-group">
                    <label for="logo">logo:</label>
                    <input id="logo" name="logo" type="file" class="form-control">
                    <input id="logoUrl" name="logoUrl" type="text" class="form-control" placeholder="http url" onchange="hideFile(this)">
                </div>
                <div class="form-row form-group">
                    <label for="ico">ico:</label>
                    <input id="ico" name="ico" type="file" class="form-control">
                    <input id="icoUrl" name="icoUrl" type="text" class="form-control" placeholder="http url" onchange="hideFile(this)">
                </div>
                <div class="form-row form-group">
                    <label for="redirectUrl">跳转:</label>
                    <input id="redirectUrl" name="redirectUrl" type="text" class="form-control">
                </div>
                <div class="form-group">
                    <label for="open">是否公开:</label>
                    <select id="open" name="open" class="form-control">
                        <option value="1" selected>是</option>
                        <option value="0">否</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="type">类型:</label>
                    <select id="type" name="type" class="form-control">
                        <option value="1" selected>公共</option>
                        <option value="2">运营</option>
                        <option value="3">研发</option>
                        <option value="99">其它</option>
                    </select>
                </div>
                <div class="form-row form-group">
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
#end

#define script()
<script>
    function add(){
        var name = $("#name").val();
        if(name === undefined || name=== ''){
            alert("名称不能为空");
            return false;
        }
    }
    function hideFile(url) {
        console.log(url.value);
        var value = url.value;
        var id  = url.id;
        if(value !== undefined && value !== ''){
            if(!IsURL(value)){
                alert("请输入正确的网址");
                url.value='';
                if(id === "logoUrl"){
                    $("#logo").show();
                } else {
                    $("#ico").show();
                }
                return;
            }
            if(id === "logoUrl"){
                $("#logo").hide();
            } else {
                $("#ico").hide();
            }
        } else {
            if(id === "logoUrl"){
                $("#logo").show();
            } else {
                $("#ico").show();
            }
        }
    }
    function IsURL (str_url) {
        var strRegex = '^((https|http|ftp|rtsp|mms)?://)'
            + '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184
            + '|' // 允许IP和DOMAIN（域名）
            + '([0-9a-z_!~*\'()-]+.)*' // 域名- www.
            + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名
            + '[a-z]{2,6})' // first level domain- .com or .museum
            + '(:[0-9]{1,4})?' // 端口- :80
            + '((/?)|' // a slash isn't required if there is no file name
            + '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$';
        var re=new RegExp(strRegex);
        //re.test()
        if (re.test(str_url)) {
            return true;
        } else {
            return false;
        }
    }
</script>
#end